import { PageResult } from "~/search";
import { PageDto, PageData, PutDto, PutRes, DisableDto, DisableRes } from "~/rest";

import { Gateway, getGateway } from "@/droplet-bus/core.define";
import { app_gateway } from "./core.local";
import { Media, MediaGroup } from "./schema.media";
import { ENUM_MEDIA_PREFIX } from "./core.define";

export const MediaGroupGateway: Gateway = getGateway(app_gateway, "pond_media_group");
export type putMediaGroupDto = PutDto<MediaGroup>;
export type disableMediaGroupDto = DisableDto;
export interface MediaGroupInterfaceWithPrimary<T> {
  get(dto: T): Promise<PageResult<MediaGroup>>;
  put(dto: T & putMediaGroupDto): Promise<PutRes<MediaGroup>>;
  disable(dto: T & disableMediaGroupDto): Promise<DisableRes>;
}

export const MediaGateway: Gateway = getGateway(app_gateway, "pond_media");
export type getMediaDto = PageDto<Media> & { groupId: MediaGroup["id"] };
export type putMediaDto = PutDto<Media>;
export type disableMediaDto = DisableDto;
export type getWriteSignDto = { fileName: string; suffix: string; prefix: ENUM_MEDIA_PREFIX };
export type getReadURLDto = { mediaId: Media["id"] };
export type getOcrFaPiaoDto = { mediaIds: Media["id"][] };

export interface MediaInterfaceWithDerive<T> {
  get(dto: T & getMediaDto): Promise<PageData<Media>>;
  put(dto: T & putMediaDto): Promise<PutRes<Media>>;
  disable(dto: T & disableMediaDto): Promise<DisableRes>;

  //
  getWriteSign(dto: T & getWriteSignDto): Promise<{ URL: string; media: Media }>;
  getReadURL(dto: T & getReadURLDto): Promise<{ URL: string }>;

  /** 识别发票 */
  getOcrFaPiao(dto: T & getOcrFaPiaoDto): Promise<{ mediaId: Media["id"]; textList: { Name: string; Value: string }[] }[]>;
}
